#!/usr/bin/perl -wT

# cord@debian.org

use strict;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);

my $logfile = '/org/lists.debian.org/spam-log/msgid-nominator.log';
my $output;

print header;

unless (param('Quiet')) {
  open (HEADER, "/org/lists.debian.org/html/header.in") or 
    die ("$0: can't open /org/lists.debian.org/html/header.in: $!\n");
  while (<HEADER>) {
    s/u_TITLE_u/Listarchive Review Nomination/;
    print;
  }
  close (HEADER);

  print "<h2>Nominate</h2>\n";

  print "<hr noshade width=\"100%\" size=\"1\">\n";

  print p("Please enter a Message-Id to nominate a post for the review process.");

  print start_form(-method=>'GET');

  print p("Message-ID:", textfield('msgid'), 
	checkbox(-name=>'Quiet'));

  print submit('Nominate for Review');
  print end_form;
}

if (param()) {
  if ($ENV{'REMOTE_ADDR'} =~ m#^195.154.75.109$#) {
    $output = "FAIL: you are blocked from reporting - Please contact listmaster\@lists.debian.org";
  } elsif (param('msgid') =~ m#^\s*(<?[-\w\d\.%@]+>?).*\s*$#) {
    open (LOG, ">>$logfile") or die ("$0: can't open $logfile for writing: $!\n");
    print LOG "time: " . time . "; addr: $ENV{'REMOTE_ADDR'}; msg-id: $1\n"; 
    close LOG;
    $output = "OK: nominated $1";
  } else {
    $output = "FAIL: invalid characters - Please contact listmaster\@lists.debian.org with your message-id";
  }

  unless (param('Quiet')) {
    print p($output);
    open (FOOTER, "/org/lists.debian.org/html/footer.in") or 
      die ("$0: can't open /org/lists.debian.org/html/footer.in: $!\n");
    while (<FOOTER>) {
      print;
    }
    close (FOOTER);
  } else {
    print "$output\n";
  }
}
